package controller;

import dao.ClassDao;
import model.StudentClass;
import utils.PageUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/classList")
public class ClassListServlet extends HttpServlet {

    public static final Integer PageSize = 2;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取查询条件
        String classType = req.getParameter("class_type");
        String dnoName = req.getParameter("dno_name");
        ClassDao classAll=new ClassDao();
        ArrayList<StudentClass> classList = classAll.query_all_class();
        //查询第一个条件
      /*  List<StudentClass> classnames = new ArrayList<StudentClass>();
        if (null != classType && !"".equals(classType)) {
            for (StudentClass class1 : classList) {
                if (class1.getClassName().contains(classtype)) {
                    classNames.add(class1);
                }
            }
        } else {
            classnames = classList;
        }
        //查询第二个条件
        List<StudentClass> dnos= new ArrayList<StudentClass>();
        if (null != dnoName && !"".equals(dnoName)) {
            for (StudentClass class2 : listClass) {
                if (class2.Dno().contains(dnoName)) {
                    dnos.add(class2);
                }
            }
        } else {
            dnos = listClass;
        }*/
        //获取当前页
        String strPageNumb = req.getParameter("pageNumb");
        Integer pageNumb = 1;
        if (null != strPageNumb && !"".equals(strPageNumb)) {
            pageNumb = Integer.valueOf(strPageNumb);
        }
    /*    for (int i = 1; i <= goods.size(); i++) {
            Goods good = goods.get(i-1);
            good.setGoodsNum(i);
        }*/
        //初始化pager对象
        PageUtils page = new PageUtils(pageNumb, PageSize, classList);
        req.setAttribute("page", page);
    //    req.setAttribute("goodsType", goodsType);
     //   req.setAttribute("goodsName", goodsName);
        req.getRequestDispatcher("/classPage.jsp")
                .forward(req, resp);
    }
}

